#pragma once
#include <string>
#include <tinystr.h>
#include <tinyxml.h>
#include <list>
#include <vector>

//Enumerate that holds the types of nodes
enum eConversationNodeType
{
  eNormalTalk,
  eChooseTalk,
  eEndConversation
};

//Struct to hold the conversation tree
struct cConversationNode
{
  eConversationNodeType meType;
  std::string macText;
  float mfDuration;
  int miCharacterId;

  typedef std::vector<cConversationNode> cConversationChildren;
  typedef cConversationChildren::iterator cConversationChildrenIt;

  cConversationChildren mChildren;
};

//Struct to hold information relative to character speaker
struct cCharacterSpeaker
{
  int miCharacterId;
  std::string macCharacterName;
};

//Struct to hold information relative to conversations
struct cConversation
{
  std::string macName;
  cConversationNode mRoot;
};

//Conversation manager class
class cConversationManager
{ 
  private:
    //Type definition to simplify the syntax
    typedef std::vector<cCharacterSpeaker> cCharacters;
    typedef cCharacters::iterator cCharactersIt;
    typedef std::list<cConversation> cConversations;
    typedef cConversations::iterator cConversationsIt;
    typedef std::vector<cConversationNode> cConversationChildren;
    typedef cConversationChildren::iterator cConversationChildrenIt;

    //List of characters
    cCharacters mCharacters;
    //List of conversations 
    cConversations mConversations;
    //Current conversation node
    cConversationNode *mpCurrentConversationNode;
    //Time to show the conversation
    float mfMessageTime;
    //Selected option in a choose conversation
    unsigned muiChooseOption;


    void ParseNode(TiXmlElement *pElem, cConversationNode *pCurrentNode);
    void ParseCharacter(TiXmlElement *pElem);
    void ParseConversation(TiXmlElement *pElem);
    void NextMessage(unsigned luiNextMessageIndex);
  public:
    void Init(const std::string &lacConversationFile);
    void Deinit(void);
    void Update(float lfTimeStep);
    void Render();
    void StartConversation(const std::string &lacConversationId);
    bool IsInConversation();


};

